  <?php
error_reporting(E_ALL ^ E_DEPRECATED);
?>
<?php
	/*************************************/
	/*    文件名：finish.php	         */
	/*    功能：数据chuli	 */
	/*************************************/

	include "dbconnect.php";
	
	$act = isset($_REQUEST['act']) ? $_REQUEST['act'] : '';
	
	//?定???信息数?，以及相?信息。
	$error = array();	
	$message = "<p><b>系统提示：非法操作！</b></p>";
	$button = "<input value=\" 返 回 \" type=\"button\" onclick=\"history.back()\">\n";

	if(empty($_POST['name'])){
		$error[] = "用户名没有填写！";
	}
	if(empty($_POST['comment'])){
		$error[] = "留言内容没有填写！";
	}
	if(count($error))
	{
		$message  = "<p><b>系统发现以下错误，请修正！</b>\n";
		$message .= "<ul>\n";
		foreach($error as $err){
			$message .= "<li>$err</li>\n";
		}
		$message .= "</ul></p>\n";
		$button = "<input value=\" 返 回 \" type=\"button\" onclick=\"history.back()\">\n";
	}
	else	
	{
	  if(isset($_POST['id']))
		{$id		  = intval($_POST['id']);}
		$ni     = intval($_POST['ni']);
		$name    = mysql_real_escape_string(stripcslashes($_POST['name']));
		$comment = mysql_real_escape_string(stripcslashes($_POST['comment']));
		if($act=='write')
		{
			//插入数据?
			$sql = "INSERT INTO guestbook (name,  ni, comment, postdtm)
					VALUES ('$name', '$ni','$comment', NOW())";

		}
		elseif($act=='edit')
		{
			//更新数据?
			$sql = "UPDATE guestbook SET
					name = '$name', 
					ni = '$ni', 
					comment = '$comment',
					postdtm = NOW()
					WHERE id = $id";
		}

		$res = mysql_query($sql);
		echo mysql_error();
		if(mysql_affected_rows()>0)
		{
			$message = "<p><b>留言内容已经存储成功！</b></p>\n";
			$button = "<input value=\" 返 回 首 页 \" type=\"button\" onclick=\"location.href='index.php'\">\n";
		}
		else
		{
			$message = "<p><b>留言内容存储失败！</b></p>\n";
			$button = "<input value=\" 返 回 上一 页 \" type=\"button\" onclick=\"history.back()\">\n";
		}
	}

?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>输出结果</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
 <div align="center" >
 <table width="90%" border="0" cellpadding="4" cellspacing="1">
  <tr>
   <td width="100%" class="HeaderRow">系统信息</td>
  </tr>
  <tr>
   <td class="SubTitleRow">
<span class="redfont">
	<br>
	<?php echo $message ?>
	<br>
</span></td>
  </tr>
  <tr>
   <td align="center">
	<?php echo $button ?>
   </td>
  </tr>
 </table>
 </div>
</body>
</html>
